﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using NLBS.Views;
using NLBS.Framework;
using NLBS.Data.Business;

namespace NLBS.Validate
{
    public class GuestBookAddValidate : ValidateTemplete<GuestBook>
    {
        private ICommentAction<GuestBook> guestBookAction;
        private ICommentFormView commentFrom;
        private CommentAddValidate commentValidate;
        public GuestBookAddValidate(ICommentFormView commentFrom, ICommentAction<GuestBook> gbAction, CommentAddValidate cv)
        {
            this.commentFrom = commentFrom;
            this.guestBookAction = gbAction;
            commentValidate = new CommentAddValidate(commentFrom);
        }

        public override void checkPower()
        {
            commentValidate.checkPower();
        }

        public void checkPostDuration()
        {
            commentValidate.checkPostDuration();
        }

        public void checkLogin()
        {
            commentValidate.checkLogin();
        }

        public override void checkArgument()
        {
            commentValidate.checkArgument();
        }

        public override void checkPowerAgain()
        {
            throw new NotImplementedException();
        }

        public override void checkEntity()
        {
            throw new NotImplementedException();
        }

        public void Validate(CallValid valid, CallError error)
        {
            try
            {
                checkPower();
                checkPostDuration();
                checkLogin();
                checkArgument();
            }
            catch (System.Exception e)
            {
                error(e.Message);
            }
            valid();
        }

        public void ValidateGetSingle(CallValid valid, CallError error)
        {

        }

        public void ValidateDelete(CallValid valid, CallError error)
        {
            try
            {
                if (BlogInfo.Instance().EnableGuestBook == 0)
                {
                    Error = "禁用留言板";
                    return;
                }
                if (power.Delete < 1)
                {
                    Error = "没有权限删除留言";
                    return;
                }
                GuestBook gb = GuestBookData.GetGuestBookByID(this.keyID);
                if (gb == null)
                {
                    Error = "留言不存在";
                    return;
                }
                User user=BlogInfo.Instance().CurrentUser;
                if (user.UserID != gb.UserID && user.Group.GroupID != 1 && power.Delete < 2)
                {
                    Error = "没有权限删除留言";
                    return;
                }
            }
            catch (System.Exception e)
            {
                error(e.Message);
            }
            valid();
        }
    }
}
